package com.maxjay.system.dao.jdbc;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashSet;
import java.util.Set;

import org.apache.log4j.Logger;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.ResultSetExtractor;
import org.springframework.stereotype.Repository;

import com.maxjay.system.dao.RoleDao;

@SuppressWarnings({"rawtypes", "unchecked"})
@Repository
public class RoleDaoJdbc extends BaseDaoJdbc implements RoleDao {

	private static Logger logger = Logger.getLogger(RoleDaoJdbc.class);
	
	public Set<String> getRoleUsers(String roleId) {
		String sql = "select t1.USER_ID from T_SYS_USER_ROLE t1 where t1.ROLE_ID=?";
		logger.debug("查询角色[ROLE_ID:" + roleId + "]下的用户SQL为：" + sql);
		Set<String> roleUsers = (Set<String>)this.getJdbcTemplate().query(sql, 
				new Object[]{ roleId }, new ResultSetExtractor() {
			Set<String> users = new HashSet<String>();
			public Object extractData(ResultSet rs) throws SQLException, DataAccessException {
				while(rs.next()){
					users.add(rs.getString(1));
				}
				return users;
			}
		});
		return roleUsers;
	}

}
